package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.PcbApproveProcess;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface PcbApproveProcessDao {
    @Results(id = "pcbApproveProcessResultMap", value = {
            @Result(column = "pcb_approve_process_id", property = "pcbApproveProcessId", jdbcType = JdbcType.INTEGER),
            @Result(column = "approve_type", property = "approveType", jdbcType = JdbcType.INTEGER),
            @Result(column = "data_id", property = "dataId", jdbcType = JdbcType.INTEGER),
            @Result(column = "old_status", property = "oldStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "new_status", property = "newStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "file_ids", property = "fileIds", jdbcType = JdbcType.VARCHAR),
            @Result(column = "approve_node", property = "approveNode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "approve_user_id", property = "approveUserId", jdbcType = JdbcType.INTEGER),
            @Result(column = "approve_user_name", property = "approveUserName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "approve_to_id", property = "approveToId", jdbcType = JdbcType.INTEGER),
            @Result(column = "approve_to_name", property = "approveToName", jdbcType = JdbcType.VARCHAR),
    })

    /*
     *查询单个
     */
    @Select("<script> " +
            "select " +
            "* " +
            "from " + DB2TableName.PCB_APPROVE_PROCESS +
            " where pcb_approve_process_id = #{id}" +
            "</script>")
    PcbApproveProcess getById(@Param("id") Integer id);

    /*
     *查询指定行数据
     */
    @Select("<script> " +
            "select pcb_approve_process_id, approve_type, data_id, old_status, new_status, remark, approve_node, approve_user_id, approve_user_name, apply_to_id, apply_to_name, create_time, file_ids " +
            " from " + DB2TableName.PCB_APPROVE_PROCESS +
            "<where>" +
            "<if test='approveType != null'>" +
            " and approve_type = #{approveType}" +
            "</if>" +
            "<if test='dataId != null'>" +
            " and data_id = #{dataId}" +
            "</if>" +
            "</where>" +
            " order by create_time desc" +
            "</script>")
    @ResultMap(value = "pcbApproveProcessResultMap")
    List<PcbApproveProcess> getByLimit(PcbApproveProcess param);

    @Insert("insert into " + DB2TableName.PCB_APPROVE_PROCESS + "(approve_type, data_id, old_status, new_status, remark, approve_user_id, create_time, file_ids, approve_node, approve_user_name, apply_to_id,apply_to_name) " +
            "values (#{approveType}, #{dataId}, #{oldStatus}, #{newStatus}, #{remark}, #{approveUserId}, #{createTime}, #{fileIds}, #{approveNode}, #{approveUserName}, #{applyToId}, #{applyToName})")
    @Options(useGeneratedKeys = true, keyProperty = "pcbApproveProcessId")
    Integer insert(PcbApproveProcess pcbApproveProcess);

    /*
     *通过主键删除
     */
    @Delete("delete from " + DB2TableName.PCB_APPROVE_PROCESS + " where pcbApproveProcessId = #{id} ")
    Integer delete(@Param("id") Integer id);

    @Delete("delete from " + DB2TableName.PCB_APPROVE_PROCESS + " where approve_type = #{flowType} and data_id = #{dataId} ")
    Integer deleteByDataId(@Param("flowType") Integer flowType, @Param("dataId") Integer dataId);

    /*
     *通过主键修改数据

    @Update("<script>" +
            "update "+ DB2TableName.PCB_APPROVE_PROCESS +
            "<set>" +
            "<if test='approveType != null'>" +
            "approve_type = #{approveType}," +
            "</if>" +
            "<if test='dataId != null'>" +
            "data_id = #{dataId}," +
            "</if>" +
            "<if test='oldStatus != null'>" +
            "old_status = #{oldStatus}," +
            "</if>" +
            "<if test='newStatus != null'>" +
            "new_status = #{newStatus}," +
            "</if>" +
            "<if test='approveUserId != null'>" +
            "approve_user_id = #{approveUserId}," +
            "</if>" +"<if test='remark != null'>" +
            "remark = #{remark}," +
            "</if>" +
            "<if test='createTime != null'>" +
            "create_time = #{createTime}," +
            "</if>" +
            "<if test='fileId != null'>" +
            "file_id = #{fileId}," +
            "</if>" +
            "</set>" +
            "where pcb_approve_process_id = #{pcbApproveProcessId}" +
            "</script>")
    Integer update(PcbApproveProcess param); */
}
